﻿<cfsilent>
	<cfscript>

		event.setArg("pageTitle", "教材管理 - 教材基础信息 - 征订目录");
		
		strAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		
		pubId = event.getArg("PubID");

		pubExId = event.getArg("publisherExistsID");
		bookExId = event.getArg("bookExistsID");

		rs_book = queryNew("bid");
		rs_bookIndex = queryNew("pyid");
		rs_publisherEntity = queryNew("pid");
		
		/* 读取出版社统计信息 */
		sql = "	SELECT
					p.pid,p.publisher,p.book_count,p.pyid
				FROM
					t_publisher p
				WHERE
					p.pyid != '0'
				ORDER BY
					p.publisher";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_pub = queryObj.execute(sql=sql).getResult();

		sql = "	SELECT
					DISTINCT p.pyid
				FROM
					t_publisher p
				WHERE
					p.pyid != '0'
				ORDER BY
					p.pyid";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_pubIndex = queryObj.execute(sql = sql).getResult();
		
		currentTab = event.getArg("TabID", "labPublisher");
		
		targetArgs = structNew();
		
		if (len(pubId)) {
			
			/* 读取出版社目录信息 */
			sql = "	SELECT
						p.publisher,p.pid,p.book_count
					FROM
						t_publisher p
					WHERE
						p.pid = :pubId ";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name = "pubId", value = pubId, cfsqltype = "cf_sql_char");
			rs_publisherEntity = queryObj.execute(sql = sql).getResult();
			
			if ( rs_publisherEntity.recordCount ) {

				currentTab = "labBooks";
				
				sql = "	SELECT
							b.bid,b.book_name,b.book_edition,b.book_authors,b.book_prise,b.pyid,b.book_isbn
						FROM
							t_book b
						WHERE
							b.pid = :pubId 
						ORDER BY
							b.book_name";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "pubId", value = pubId, cfsqltype = "cf_sql_char");
				rs_book = queryObj.execute(sql = sql).getResult();
				
				/* 生成首字母索引 */		
				
				sql = "	SELECT
							DISTINCT b.pyid
						FROM
							t_book b
						WHERE
							b.pid = :pubId 
						ORDER BY
							b.pyid";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "pubId", value = pubId, cfsqltype = "cf_sql_char");
				rs_bookIndex = queryObj.execute(sql = sql).getResult();
			}
			
		}
		
		/* 检查书库的ISBN编号是否有重复 */
		sql = "	SELECT
					b.book_isbn
				FROM
					t_book b
				GROUP BY
					b.book_isbn
				HAVING
					COUNT(*) > 1";
		
		queryObj = new Query(datasource = application.dnsSlave);
		rs_dumpISBN = queryObj.execute(sql = sql).getResult();
		
		if ( rs_dumpISBN.recordCount ) {
			currentTab = "labChecker";
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('bookOther')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">自编讲义及翻印教材</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>教材征订目录
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
			
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labPublisher">class="active"</cfif> id="labPublisher" tabTarget="Publisher">出版社列表</span>
						<cfif rs_publisherEntity.recordCount>
							<span <cfif currentTab eq "labBooks">class="active"</cfif> id="labBooks" tabTarget="Books"><cfoutput>#rs_publisherEntity.publisher#</cfoutput></span>
							
							<cfif rs_pub.recordCount gt 1>
								<span <cfif currentTab eq "labCombo">class="active"</cfif> id="labCombo" tabTarget="Combo">合并出版社信息</span>
							</cfif>
							
						</cfif>
						
						<cfif rs_dumpISBN.recordCount>
							<span <cfif currentTab eq "labChecker">class="active"</cfif> id="labChecker" tabTarget="Checker">教材数据纠错</span>
						</cfif>
						
						<span <cfif currentTab eq "labImport">class="active"</cfif> id="labImport" tabTarget="Import">导入出版教材信息</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Publisher" class="tabContent">
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						function showCreateFrom() {
							$("form#formCreate").toggleClass("hidden_elem");
							$("div#pubList").toggleClass("hidden_elem");
							return void(0);
						}
								
						<cfif len(pubExId)>
						$(document).ready(function() {
							showCreateFrom();
						});
						</cfif>
								
						// -->
						//]]>				
					</script>

					<cfif rs_pub.recordCount>
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('bookDownloadExcel')#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载全部教材信息</span></a>
								</div>
								<h3>教材出版社信息</h3>
								<p><span class="img icon16x16 message"></span>这里列出的是现有教材征订目录的出版社信息. 如果您需要设置新的出版社, <a href="javascript:showCreateFrom();">可以通过点击这里进行</a></p>
								<hr/>
								<div class="UIArrangeOper">
									<cfif rs_pubIndex.recordCount>
										<span>出版社索引</span>
                                        <cfloop query="rs_pubIndex">
											<a class="opBtn Index letterFilter" href="#pos<cfoutput>#rs_pubIndex.pyid#</cfoutput>"><cfoutput>#rs_pubIndex.pyid#</cfoutput></a>
										</cfloop>
									</cfif>
								</div>
							</div>

							<div id="pubList">
							
								<cfloop query="rs_pubIndex">
									<div class="noticeBlock">
										<p><b><cfoutput>#rs_pubIndex.pyid#</cfoutput></b><a name="pos<cfoutput>#rs_pubIndex.pyid#</cfoutput>"></a></p>
										<hr/>
									</div>
								
									<div class="clearfix">
										<div class="UICardTable">
                                            <cfloop query="rs_pub">
												<cfif rs_pubIndex.pyid eq rs_pub.pyid>
													<cfset structInsert(targetArgs, "PubID", rs_pub.pid, true) />
													<dl <cfif listFind(pubExId, rs_pub.pid)>class="warn"</cfif>>
														<dt>
															<a href="<cfoutput>#buildURL('bookSchema', targetArgs)#</cfoutput>">
																<em class="building"><!--imgholder--></em>
																<dd>
																	<h3><cfoutput>#replace( replace(rs_pub.publisher, " ", "&not;", "all"), CHR(13), "&not;", "all")#</cfoutput></h3>
																	<div>注册教材<span><cfoutput>#rs_pub.book_count#</cfoutput></span>本</div>
																</dd>
															</a>
														</dt>
													</dl>
												</cfif>
											</cfloop>
										</div>
									</div>
								
								</cfloop>
								
								<cfset structDelete(targetArgs, "PubID") />
								
							</div>

						<cfelse>
							<div class="systemNotice">
								<h3><span class="img icon16x16 info"></span>没有设置任何出版社</h3>
								<p>当前您还没有设置出版社信息, 请通过完善下列表单设置教材征订目录的第一个出版社.</p>
							</div>
					</cfif>
					
					<!-- createPublisher -->
					<form id="formCreate" onSubmit="javascript:return processVerfiyForm('formCreate');" class="formWrapper <cfif rs_pub.recordCount>hidden_elem</cfif>" method="post" action="<cfoutput>#buildURL('publisherCreateDo')#</cfoutput>">
							
						<div class="label">
							<span class="req">*</span><b>出版社正式名称</b>
							<input name="Publisher" id="Publisher" type="text" class="typeTextShort" verification="required" maxlength="30" value="<cfoutput>#event.getArg('Publisher')#</cfoutput>" />
							<cfif len(pubExId)>
								<p class="notice">该出版社名称已在系统注册过了.</p>
							</cfif>
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button" type="submit" value="提交" />
							<input onclick="showCreateFrom();" class="button1" type="reset" value="返回" />
						</div>
					</form>
					<!-- /createPublisher -->
					
				</div>
				
				<cfif rs_publisherEntity.recordCount>
					
					<cfset structInsert(targetArgs, "PubID", rs_publisherEntity.pid, true)/>
					
					<div id="Books" class="tabContent">
						
						<div class="noticeBlock">
							
							<div class="operation">
								<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('publisherBookDownloadExcel', targetArgs)#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载出版社教材信息</span></a>
							</div>
							
							<h3><cfoutput>#rs_publisherEntity.publisher#</cfoutput></h3>
							<p>
								<span class="img icon16x16 message"></span>
								出版社现有注册教材信息<em><cfoutput>#rs_publisherEntity.book_count#</cfoutput></em>条.
								如需要设置新的教材, <a href="javascript:showCreateBookFrom();">可以通过点击这里进行</a>. 
							</p>
							<cfif rs_book.recordCount eq 0>
								<p>
									<span class="img icon16x16 message"></span>
									如果需删除该出版社, <a href="javascript:showDeleteFrom();">点这里删除</a>. 
								</p>
							</cfif>
							<hr/>
							
							<div class="UIArrangeOper">
								<cfif rs_bookIndex.recordCount>
									<span>书名索引</span>
                                    <cfset i = 0 />
                                    <cfloop query="rs_bookIndex">
										<a class="opBtn Index letterFilter"><cfoutput>#rs_bookIndex.pyid#</cfoutput></a>
									</cfloop>
									<a class="opBtn Index selected letterReset">ALL</a>
									<script language="javascript" type="text/javascript">
										//<![CDATA[
										<!--
										$(document).ready(function() {
											
											$("a.letterReset").click(function(){
												
												$("a.letterReset").addClass("selected");
												$("a.letterFilter").removeClass("selected");
												
												$("tr[idxletter]", $("#bookList > tbody")).removeClass("hidden_elem");
											});
											
											$("a.letterFilter").click(function(){
												
												$("a.letterReset").removeClass("selected");
												$("a.letterFilter").removeClass("selected");
												
												$(this).addClass("selected");
												
												
												var letter = $(this).text();

												$("tr[idxletter!='" + letter + "']", $("#bookList > tbody")).addClass("hidden_elem");
												$("tr[idxletter='" + letter + "']", $("#bookList > tbody")).removeClass("hidden_elem");
												
												
											});
											
										});
										// -->
										//]]>
									</script>
								</cfif>
							</div>
						</div>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							function showCreateBookFrom() {
								$("form#formCreateBook").toggleClass("hidden_elem");
								$("table#bookList").toggleClass("hidden_elem");
								return void(0);
							}
							
							function showDeleteFrom() {
								$("div#deleteNotice").toggleClass("hidden_elem");
								return void(0);
							}
							
							<cfif len(bookExId)>
							$(document).ready(function() {
								showCreateBookFrom();
							});
							</cfif>
							
							// -->
							//]]>				
						</script>
						
						<cfif rs_book.recordCount>
							
							<cfset structInsert(targetArgs, "PubID", pubId, true) />
							
							<table id="bookList" class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td>书名</td>
										<td>作者</td>
										<td>版次</td>
										<td>ISBN</td>
										<td>定价</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
                                    <cfloop query="rs_book">
										<cfset row++ />
										<cfset structInsert(targetArgs, "BID", rs_book.bid, true) />
										<tr class="editRows" rowid="<cfoutput>#rs_book.bid#</cfoutput>" idxletter="<cfoutput>#rs_book.pyid#</cfoutput>">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><cfoutput>#rs_book.book_name#</cfoutput></td>
											<td><cfoutput>#listFirst(rs_book.book_authors, "/")#</cfoutput><cfif listLen(rs_book.book_authors, "/") gt 1> `等</cfif></td>
											<td nowrap="nowrap"><cfoutput>#dictAdvice.getBookEdition(rs_book.book_edition)#</cfoutput></td>
											<td width="150"><span class="numeric"><cfoutput>#dictAdvice.getISBN(rs_book.book_isbn)#</cfoutput></span></td>
											<td width="50"><span class="numeric"><cfif rs_book.book_prise gt 0><cfoutput>#numberFormat(rs_book.book_prise, "_.__")#</cfoutput><cfelse>-/-</cfif></span></td>
											<td><a href="<cfoutput>#buildURL('bookDetail', targetArgs)#</cfoutput>" class="operation"></a></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
						</cfif>
						
						<cfif rs_book.recordCount eq 0>
							<!-- deletePublisher -->
							<div id="deleteNotice" class="systemNotice hidden_elem">
								<h3><span class="img icon16x16 info"></span>删除出版社信息</h3>
							
								<form id="formRemove" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('publisherRemoveDo')#</cfoutput>">
									<input name="PubID" type="hidden" value="<cfoutput>#rs_publisherEntity.pid#</cfoutput>" />
									<div class="lable"><input class="button2" type="submit" value="删除出版社" /></div>
								</form>
							</div>
							<!-- /deletePublisher -->
						</cfif>
						
						<!-- createBook -->
						<form id="formCreateBook" onSubmit="javascript:return processVerfiyForm('formCreateBook');" class="formWrapper hidden_elem" method="post" action="<cfoutput>#buildURL('bookCreateDo')#</cfoutput>">
							
							<input name="PubID" type="hidden" value="<cfoutput>#rs_publisherEntity.pid#</cfoutput>" />
							
							<div class="label">
								<span class="req">*</span><b>书名</b>
								<input name="BookName" id="BookName" type="text" class="typeTextShort" verification="required" maxlength="80" value="<cfoutput>#event.getArg('BookName')#</cfoutput>" />
							</div>

							<div class="label">
								<span class="req">*</span><b>作者</b>
								<input name="Authors" id="Authors" type="text" class="typeTextShort" verification="required" maxlength="50" value="<cfoutput>#event.getArg('Authors')#</cfoutput>" />
							</div>
							
							<div class="label">
								<span class="req">*</span><b>定价</b>
								<input name="Prise" id="Prise" type="text" class="typeSmallInt" verification="double" maxlength="7" value="<cfoutput>#event.getArg('Prise','0.00')#</cfoutput>" />
							</div>

							<hr/>
							
							<div class="label">
								<b>ISBN</b>
								<input name="ISBN" id="ISBN" type="text" class="typeISBN <cfif len(bookExId)>typeError</cfif>" verification="ISBN" maxlength="17" value="<cfoutput>#event.getArg('ISBN')#</cfoutput>" />
								<cfif len(bookExId)>
									<p class="notice">该 ISBN 号在系统中已被注册</p>
								</cfif>
							</div>
							
							<div class="label">
								<b>版次</b>
								<select name="Edition1" class="inlinePart">
									<option value="YYYY">未知</option>
									<cfloop from="#year(now())#" to="#year(now())-25#" step="-1" index="e">
										<option value="<cfoutput>#e#</cfoutput>"><cfoutput>#e#</cfoutput>年</option>
									</cfloop>
								</select>
								<select name="Edition2" class="inlinePart">
									<cfloop from="1" to="9" index="e">
										<option value="<cfoutput>#e#</cfoutput>">第<cfoutput>#strAdvice.ChineseNumber(e)#</cfoutput>版</option>
									</cfloop>
								</select>
							</div>
							
							<div class="label">
								<b>获奖情况及其他</b>
								<textarea name="Awards"><cfoutput>#event.getArg('Awards')#</cfoutput></textarea>
							</div>

							<hr/>
						
							<div class="lable">
								<input class="button" type="submit" value="提交" />
								<input onclick="showCreateBookFrom();" class="button1" type="reset" value="返回" />
							</div>
						</form>
						<!-- /createBook -->
						
					</div>
				</cfif>
				
				<cfif rs_pub.recordCount gt 1 and rs_publisherEntity.recordCount>
					<div id="Combo" class="tabContent">
					
						<div class="noticeBlock">
							<h3>合并出版社信息</h3>
							<p><span class="img icon16x16 message"></span>在批量导入教材数据时, 由于出版社名称填写不规范会造成多个一个出版社出现多个记录. 在这里可以对冗余出版社信息进行合并.</p>
							<hr/>
						</div>
					
						<!-- publisherCombo -->
						<form id="formCombo" onSubmit="javascript:return processVerfiyForm('formCombo');" class="formWrapper" method="post" action="<cfoutput>#buildURL('publisherComboDo')#</cfoutput>">
						
							<input type="hidden" name="oldPubID" value="<cfoutput>#rs_publisherEntity.pid#</cfoutput>" />
							
							<div class="label">
								<span class="req">*</span><b>将出版社</b>
								<cfoutput>#replace(rs_publisherEntity.publisher, " ", "&not;", "all")#</cfoutput>
							</div>
						
							<div class="label">
								<span class="req">*</span><b>合并到</b>
								<select name="newPubID">
                                    <cfloop query="rs_pub">
										<cfif rs_pub.pid neq rs_publisherEntity.pid>
											<option value="<cfoutput>#rs_pub.pid#</cfoutput>"><cfoutput>#replace(rs_pub.publisher, " ", "&not;", "all")#</cfoutput></option>
										</cfif>
									</cfloop>
								</select>
							</div>
							
							<hr/>
						
							<div class="lable">
								<input class="button4" type="submit" value="合并出版社及教材信息" />
							</div>
							
						</form>
					</div>
				</cfif>
				
				
				<cfif rs_dumpISBN.recordCount>
				
					<div id="Checker" class="tabContent">
						
						<div class="systemNotice">
							<h3><span class="img icon16x16 info"></span>重复的 ISBN 编号</h3>
							<p>系统检测到现有的教材注册数据中, 存在重复的<em>ISBN</em>编号. 对于出版物来说<em>ISBN</em>编号必须满足唯一性要求, 请在这里删除重复的数据项.</p>
						</div>
                        
                        <cfset sql = "SELECT 
										   a.bid, a.book_name,
										   a.book_edition, a.book_authors, 
										   a.book_prise, a.pyid, a.book_isbn 
									  FROM 
										   t_book a 
									  WHERE 
										   a.book_isbn IN (:isbns) 
									  ORDER BY 
										   a.book_name " /> 
                        
                        <cfset queryObj = new Query( datasource=application.dnsSlave ) /> 
                        <cfset queryObj.addParam( name="isbns", value=rs_dumpISBN.book_isbn, cfsqltype="cf_sql_varchar", list=true ) /> 
                        
                        <cfset rs_clean = queryObj.execute( sql=sql ).getResult() />
						
						<table id="cleanList" class="UIEditable">
							<thead>
								<tr>
									<td></td>
									<td>书名</td>
									<td>作者</td>
									<td>版次</td>
									<td>ISBN</td>
									<td>定价</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
								<cfset row = 0 />
                                <cfloop query="rs_clean">
									<cfset row++ />
									<cfset structInsert(targetArgs, "BookID", rs_clean.bid, true) />
									<tr class="editRows" rowid="<cfoutput>#rs_clean.bid#</cfoutput>" idxletter="<cfoutput>#rs_clean.pyid#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_clean.book_name#</cfoutput></td>
										<td><cfoutput>#listFirst(rs_clean.book_authors, "/")#</cfoutput><cfif listLen(rs_clean.book_authors, "/") gt 1> `等</cfif></td>
										<td nowrap="nowrap"><cfoutput>#dictAdvice.getBookEdition(rs_clean.book_edition)#</cfoutput></td>
										<td width="150"><span class="numeric"><cfoutput>#dictAdvice.getISBN(rs_clean.book_isbn)#</cfoutput></span></td>
										<td width="50"><span class="numeric"><cfif rs_clean.book_prise gt 0><cfoutput>#numberFormat(rs_clean.book_prise, "_.__")#</cfoutput><cfelse>-/-</cfif></span></td>
										<td><a href="<cfoutput>#buildURL('bookRemoveDo', targetArgs)#</cfoutput>" class="stat delete"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
					</div>
					
				</cfif>
				
				<div id="Import" class="tabContent">
					
					<div class="noticeBlock">
						<h3>导入出版教材数据</h3>
						<p><span class="img icon16x16 message"></span>请严格按照如下的数据模板在电子表格文件中录入教材基础数据. 点击<a href="<cfoutput>#buildURL('importBookTemplate')#</cfoutput>">下载教材基础信息录入模板</a>, 在录入信息时请勿更改第一行表头内容.</p>
						<hr/>
						<table>
							<tr>								
								<td>ISBN</td><td>出版社</td><td>书名</td><td>版次</td><td>作者</td><td>定价</td><td>获奖项目</td>
							</tr>
							<tr>
								<td>出版号</td><td>正式名称</td><td>教材全称</td><td>1/2004.2</td><td>多名作者以 , 分割</td><td>36.00</td><td>普通高等教育“十一五”国家级规划教材 或 无</td>
							</tr>
						</table>
						<hr/>
					</div>
					
					<form target="output" onSubmit="javascript:return processVerfiyForm('formImport');" id="formImport" class="formWrapper" method="post" enctype="multipart/form-data" action="<cfoutput>#buildURL('importBookDo')#</cfoutput>">
						
						<div class="label">
							<span class="req">*</span><b>导入数据文件</b>
							<input name="upload" id="upload" type="file" verification="required" />
						</div>
						
						<div class="lable"><input id="importTrigger" class="button" type="submit" value="导入教材数据" /></div>
					</form>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							$("#importTrigger").click(function(){
								$("#output").attr("src","about:blank").removeClass("hidden_elem");
							});
						});
						// -->
						//]]>
					</script>
					
					
					<iframe name="output" id="output" class="UIframeBox hidden_elem" src="about:blank" frameborder="0"></iframe>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>